package leetcode.editor.cn;

import java.util.ArrayList;
import java.util.List;

//Java：二叉树的所有路径
public class BinaryTreePaths {
    public static void main(String[] args) {
        Solution solution = new BinaryTreePaths().new Solution();
        // TO TEST
    }
    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode() {}
     * TreeNode(int val) { this.val = val; }
     * TreeNode(int val, TreeNode left, TreeNode right) {
     * this.val = val;
     * this.left = left;
     * this.right = right;
     * }
     * }
     */
    class Solution {
        List<String> result = new ArrayList<>();

        public List<String> binaryTreePaths(TreeNode root) {
            deal(root, "");
            return result;
        }

        public void deal(TreeNode node, String s) {
            if (node == null)
                return;
            if (node.left == null && node.right == null) {
                result.add(s + node.val);
                return;
            }
            String tmp = s + node.val + "->";
            deal(node.left, tmp);
            deal(node.right, tmp);
        }
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}